package com.jhhc.BDMS.Data;

import com.jhhc.BDMS.Data.Pojo.StationBO.SationInfo;
import com.jhhc.BDMS.Data.Service.GetStayionService;
import com.jhhc.FloodForecast.Sensor.Service.BDMS_ST_STBPRP_BService;
import com.jhhc.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="系统数据相关服务",tags={"站点要素相关服务"})
@RestController
@RequestMapping(value = "BDMS",headers = "Accept=application/json")
public class DataController {
    @Autowired
    private GetStayionService getStayionService;
    @Autowired
    private BDMS_ST_STBPRP_BService bService;
    //根据项目编号获取站点信息
    @ApiOperation(value = "根据项目编号获取站点信息")
    @RequestMapping( value = "Data/GetStationByProjetcId", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GetStationByProjetcId(@RequestParam Integer ProjectId){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getStayionService.getStation(ProjectId));
        return  jsonResult;
    }


    //获取要素信息
    @ApiOperation(value = "获取要素信息")
    @RequestMapping( value = "Data/GetMonitorItem", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getMonitorItem(@RequestParam Integer ProjectId,String StationCode){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);

        jsonResult.setData(getStayionService.getMonitorItem(ProjectId,StationCode));
        return  jsonResult;
    }
    //获取传感器信息
    @ApiOperation(value = "获取传感器信息")
    @RequestMapping( value = "Data/GetSensorType", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult  getSensorType(@RequestParam Integer monitorType){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getStayionService.getSensorType(monitorType));
        return  jsonResult;
    }

    @ApiOperation(value = "获取站点信息")
    @RequestMapping( value = "/GetStationInfos", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getSensorType(@RequestParam String projectId,@RequestParam(required = false) String[] sttp,
                                    @RequestParam(required = false) List<String> sensorTypes){
        JsonResult jsonResult = new JsonResult();
        if (projectId != null && !"".equals(projectId)) {
            List<SationInfo> sationInfos = bService.getStationInfos(Integer.parseInt(projectId),
                    sttp,sensorTypes);
            if (sationInfos != null && sationInfos.size() > 0) {
                jsonResult.setData(sationInfos);
            }else {
                jsonResult.setRemark("该项目编号下无站点信息");
            }

        }
        jsonResult.setSucceeded(true);
        jsonResult.setStatusCode(200);
        return  jsonResult;
    }
}
